#!/bin/bash

# update source code

TOP_DIR=$(pwd)

#CVS_OPT="-D 2013-06-01"
#SVN_OPT="-r {2013-08-03}"

if [ ! -d $TOP_DIR/source ] ; then
	mkdir $TOP_DIR/source || exit 0
	echo "create directory source"
fi

cd $TOP_DIR/source

# <1> binutils
#if [ ! -d binutils ] ; then
#	cvs -z 9 -d :pserver:anoncvs@sourceware.org:/cvs/src checkout -r binutils-2_23-branch $CVS_OPT binutils
#	mv src binutils
#else
#	cd binutils
#	cvs -z 9 update -r binutils-2_23-branch $CVS_OPT
#	cd ..
#	echo "binutils updated"
#fi
VER_BINUTILS=2.23.2
if [ ! -d binutils-$VER_BINUTILS ] ; then
	wget http://ftp.gnu.org/gnu/binutils/binutils-$VER_BINUTILS.tar.bz2
	tar xjf binutils-$VER_BINUTILS.tar.bz2
fi

# <2> gcc
#if [ ! -d gcc ] ; then
#	svn checkout $SVN_OPT svn://gcc.gnu.org/svn/gcc/branches/gcc-4_8-branch gcc
#	# svn checkout svn://gcc.gnu.org/svn/gcc/trunk gcc
#	# svn checkout svn://gcc.gnu.org/svn/gcc/branches/gcc-4_4-branch gcc
#else
#	cd gcc
#	svn switch $SVN_OPT svn://gcc.gnu.org/svn/gcc/branches/gcc-4_8-branch
##	svn update $SVN_OPT
#	cd ..
#	echo "gcc updated"
#fi
VER_GCC=4.8.2
if [ ! -d gcc-$VER_GCC ] ; then
	wget http://ftp.gnu.org/gnu/gcc/gcc-$VER_GCC/gcc-$VER_GCC.tar.bz2
	tar xjf gcc-$VER_GCC.tar.bz2
fi

# <3> gdb
#if [ ! -d gdb ] ; then
#	cvs -z 9 -d :pserver:anoncvs@sourceware.org:/cvs/src checkout -r gdb_7_6-branch $CVS_OPT gdb
#	mv src gdb
#else
#	cd gdb
#	cvs -z 9 update -r gdb_7_6-branch $CVS_OPT
#	cd ..
#	echo "gdb updated"
#fi
VER_GDB=7.6.1
if [ ! -d gdb-$VER_GDB ] ; then
	wget http://ftp.gnu.org/gnu/gdb/gdb-$VER_GDB.tar.bz2
	tar xjf gdb-$VER_GDB.tar.bz2
fi

# <4> mingw-w64
VER_MINGW64=3.0.0
if [ ! -d mingw-w64-v$VER_MINGW64 ] ; then
	wget http://downloads.sourceforge.net/project/mingw-w64/mingw-w64/mingw-w64-release/mingw-w64-v$VER_MINGW64.tar.bz2
	tar xjf mingw-w64-v$VER_MINGW64.tar.bz2
fi

# <5> gmp
VER_GMP=5.1.3
if [ ! -d gmp-$VER_GMP ] ; then
	wget http://ftp.gnu.org/gnu/gmp/gmp-$VER_GMP.tar.bz2
	tar xjf gmp-$VER_GMP.tar.bz2
fi

# <6> mpfr
if [ ! -d mpfr-3.1.2 ] ; then
	# wget http://www.mpfr.org/mpfr-current/mpfr-2.4.2.tar.bz2
	# wget https://gforge.inria.fr/frs/download.php/24926/mpfr-2.4.2.tar.bz2
	# wget http://mpfr.loria.fr/mpfr-3.0.1/mpfr-3.0.1.tar.bz2
	wget http://mpfr.loria.fr/mpfr-3.1.2/mpfr-3.1.2.tar.bz2
	tar xjf mpfr-3.1.2.tar.bz2
fi

# <7> MPC
if [ ! -d mpc-1.0.1 ] ; then
	wget http://www.multiprecision.org/mpc/download/mpc-1.0.1.tar.gz
	tar xzf mpc-1.0.1.tar.gz
fi

# <8> isl
if [ ! -d isl-0.11.1 ] ; then
	wget ftp://gcc.gnu.org/pub/gcc/infrastructure/isl-0.11.1.tar.bz2
	tar xjf isl-0.11.1.tar.bz2
fi

# <9> 
if [ ! -d cloog-0.18.0 ] ; then
	wget ftp://gcc.gnu.org/pub/gcc/infrastructure/cloog-0.18.0.tar.gz
	tar xzf cloog-0.18.0.tar.gz
fi

# <21> make
if [ ! -d make-3.82 ] ; then
	wget http://ftp.gnu.org/pub/gnu/make/make-3.82.tar.bz2
	tar xjf make-3.82.tar.bz2
fi

# <22> yasm
if [ ! -d yasm-1.2.0 ] ; then
	wget http://www.tortall.net/projects/yasm/releases/yasm-1.2.0.tar.gz
	tar xzf yasm-1.2.0.tar.gz
fi

